home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
bbs
/
pad321.zip
/
TIME.MH
< prev
next >
Wrap
Text File
|
1996-08-21
|
3KB
|
125 lines
// This file defines various time and date manipulation functions.
//
// Function list:
//
// string timeToString (struct _time: tme);
// void strToTime (string: theString, Ref struct _time: result);
//
// void timeInit ();
// bool timeToken (string: token, string: params);
//
//
#ifndef __TIME_MH
#define __TIME_MH
#ifndef __GENERAL_MH
#include "general.mh"
#endif
void setTime (Ref struct _time: dest, struct _time: source) {
dest.hh := source.hh;
dest.mm := source.mm;
dest.ss := source.ss;
}
void getTime (Ref struct _time: curTime) {
struct _stamp: curDate;
long: intDate;
intDate := time ();
long_to_stamp (intDate, curDate);
setTime (curTime, curDate.time);
}
// betweenTimes determines if testTime is within the range defined by startTime and
// endTime.
bool betweenTimes (struct _time: startTime, struct _time: endTime, struct _time: testTime) {
struct _stamp: s, e, t;
long: intStart, intTime, intEnd;
setTime (s.time, startTime);
setTime (e.time, endTime);
setTime (t.time, testTime);
intTime := stamp_to_long (t);
intStart := stamp_to_long (s);
intEnd := stamp_to_long (e);
if (intStart > intEnd) {
if ((intTime < intStart) and (intTime > intEnd)) return False;
}
else if (intStart < intEnd) {
if ((intTime < intStart) or (intTime > intEnd)) return False;
};
return True;
}
// Converts a time structure into a printable string.
//
// Format of the string is:
//
// hh:mm.ss
//
// The .ss portion is skipped if ss = 0.
//
// This will probably be rewritten to use the time format defined in MAX.CTL
// in the future.
string timeToString (struct _time: tme) {
string: result;
string: temp;
result := itostr (tme.hh);
if (strlen (result) < 2) result := "0" + result;
if (tme.mm < 10) {
temp := "0" + itostr (tme.mm);
}
else temp := itostr (tme.mm);
result := result + ":" + temp;
if (tme.ss) result := result + "." + itostr (tme.ss);
return result;
}
// strToTime converts a string containing a time into a _time struct.
// The format of the input time is:
//
// hh:mm.ss
//
// The mm and ss fields are optional, and if not included, are set
// to 0 by default.
void strToTime (string: theString, Ref struct _time: result) {
int:
hour, min, sec,
len, hourend, minend;
len := strlen (theString);
hourend := stridx (theString, 1, ':');
if (hourend = 0) {
hour := strtoi (theString);
min := 0;
sec := 0;
}
else {
hour := strtoi (substr (theString, 1, len - hourend + 1));
minend := stridx (theString, hourend+1, ':');
if (minend = 0) minend := stridx (theString, hourend+1, '.');
if (minend = 0) {
min := strtoi (substr (theString, hourend+1, len - hourend));
sec := 0;
}
else {
min := strtoi (substr (theString, hourend+1, minend - hourend));
sec := strtoi (substr (theString, minend+1, len - minend));
};
};
result.hh := hour;
result.mm := min;
result.ss := sec;
}
#endif